﻿@model IEnumerable<DefeatEpidemic.Models.Member>

<div class="layui-row">
    <span class="layui-breadcrumb">
        <a href="~/home/index">首页</a>
        <a href="~/members/Index">人员管理</a>
        <a>
            <cite>人员列表</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-xs" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1" style="line-height:25px;font-size: 10px"></i>
    </a>
</div>
<hr />

<p>
    <div class="layui-form-item">
        <label class="layui-form-label">检索</label>
        <div class="layui-input-inline">
            <input type="text" id="keyword" class="layui-input" placeholder="请输入人员姓名或身份证号" />
        </div>
        <a href="javascript:;" id="btn_search" class="layui-btn layui-btn-normal">检索</a>
        @*<a asp-action="Create" class="layui-btn">添加人员</a>*@
        <a id="export" class="layui-btn">导出</a>
    </div>
</p>
<table class="table" id="table"></table>
<script type="text/html" id="ApplicationTpl">

</script>
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-normal" href="/applications/index?member_id={{d.id}}">出入记录</a>
    @*<a href="@Url.Action("Create","Applications")?member_id={{ d.id }}" id="apply_{{ d.id }}" class="layui-btn">申请出行</a>*@
<a href="javascript:;" onclick="del('{{ d.id }}')" class="layui-btn layui-btn-danger">删除</a>
</script>
<script>
    var token =$('@Html.AntiForgeryToken()').val();
    var params = {
        url: '@Url.Action("GetList")',
        elem: '#table',
        where: '',
        size: 'lg',
        page: true,
        cols: [ //表头
            //, { field: 'id', title: 'ID', sort: true, fixed: 'left' }
            { field: 'name', title: '姓名',width:100 }
            , { field: 'idcard', title: '身份证号',width:180 }
            , { field: 'mobile', title: '联系方式',width:130 }
            , { field: 'address', title: '地址' }
            , { field: 'carNumber', title: '车牌' }
            //, { field: 'companyPlace', title: '上班地点' }
            , { field: 'created_at', title: '创建时间',width:160 }
            , { title: '操作', templet: '#operationTpl',width:320 }
        ],
        height:630
    }
    getTable(params);

    //检索
    $("#btn_search").click(function () {
        var keyword = $("#keyword").val();
        var where = {
            'keyword': keyword
        };
        params.where = where;
        getTable(params);
    })

    var export_flag = true;
    var time = 10;
    //导出
    $("#export").click(function () {        
        if (export_flag) {
            var keyword = $("#keyword").val();
            var form = $("<form>");
            var params = $('<input type="text" name="keyword" />');
            params.attr('value', keyword);
            form.attr("style", "disblay:none");
            form.attr("target", "");
            form.attr("method", "post");
            form.attr("action", "@Url.Action("Export")");
            form.append(params);
            $("body").append(form);//将表单放置在web中
            form.submit();
            export_flag = false;            
        }
        else {
            layer.msg("如果10秒后仍无反应请尝试再次点击");
        }
        setTimeout(function () {//这里的设置其实不太合理，应该是通过Ajax提交生成excel的请求，在后台生成文件后，返回下载链接，时间关系，先这么简单处理了
            export_flag=true;
        }, 10000);
    })
    

    function del(id) {
        UpdateItem("@Url.Action("Delete")", { "id": id, "__RequestVerificationToken": token }, "确定要删除该条记录吗");
    }
</script>
